using AiQiuQuan.Sport.Model.Models;
using AiQiuQuan.Sport.Core;
using AiQiuQuan.Sport.WebApi.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;

namespace AiQiuQuan.Sport.WebApi.Controllers
{
    /// <summary>
    /// 场馆会员卡管理
    /// </summary>
    public class VenueMemberCardController : ApiController
    {
        private readonly IVenueMemberCardService _venueMemberCardService;
        private readonly IVenueUserCardService _venueUserCardService;
        private readonly IVenueUserCardRecordService _venueUserCardRecordService;

        /// <summary>
        /// 场馆会员卡套管理
        /// </summary>
        public VenueMemberCardController(
            IVenueMemberCardService venueMemberCardService,
            IVenueUserCardService venueUserCardService,
            IVenueUserCardRecordService venueUserCardRecordService)
        {
            _venueMemberCardService = venueMemberCardService;
            _venueUserCardService = venueUserCardService;
            _venueUserCardRecordService = venueUserCardRecordService;
        }

        /// <summary>
        /// 查询卡套
        /// </summary>
        /// <param name="id">卡套id</param>
        [HttpGet("get")]
        public async Task<UnaryResult<VenueMemberCardDto>> GetAsync(Guid id)
        {
            var result = await _venueMemberCardService.GetAsync(id);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 卡套分页请求
        /// </summary>
        [HttpPost("pagelist")]
        [AllowAnonymous]
        public async Task<UnaryResult<PageResult<VenueMemberCardDto>>> PageListAsync(VenueMemberCardPageRequestDto request)
        {
            var result = await _venueMemberCardService.PageListAsync(request);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 卡套新增
        /// </summary>
        [HttpPost("add")]
        public async Task<UnaryResult> AddAsync(VenueMemberCardAddDto model)
        {
            var result = await _venueMemberCardService.AddAsync(model);
            return result;
        }

        /// <summary>
        /// 卡套修改状态
        /// </summary>
        [HttpPost("update_state")]
        public async Task<UnaryResult> UpdateStateAsync(VenueMemberCardUpdateStatusDto model)
        {
            var result = await _venueMemberCardService.UpdateStateAsync(model);
            return result;
        }

        /// <summary>
        /// 卡套编辑
        /// </summary>
        [HttpPost("update")]
        public async Task<UnaryResult> UpdateAsync(VenueMemberCardUpdateDto model)
        {
            var result = await _venueMemberCardService.UpdateAsync(model);
            return result;
        }

        /// <summary>
        /// 用户会员卡分页查询
        /// </summary>
        [HttpPost("usercard_pagelist")]
        public async Task<UnaryResult<PageResult<VenueUserCardDto>>> PageListAsync(VenueUserCardPageRequestDto request)
        {
            var result = await _venueUserCardService.PageListAsync(request);
            return UnaryResult.From(0, result);
        }

        /// <summary>
        /// 获取用户会员卡详情
        /// </summary>
        /// <param name="userCardId">用户会员卡id</param>
        [HttpGet("usercard_get")]
        public async Task<UnaryResult<VenueUserCardDto>> GetUserCardAsync(Guid userCardId)
        {
            var result = await _venueUserCardService.GetAsync(userCardId);
            return UnaryResult.From(0, result);
        }

        /// <summary>
        /// 用户会员卡统计信息
        /// </summary>
        /// <param name="cardId">卡套ID</param>
        [HttpPost("usercard_statistics")]
        public async Task<UnaryResult<VenueUserCardStatisticsDto>> GetUserCardStatisticsAsync([FromForm] Guid cardId)
        {
            var result = await _venueUserCardService.StatisticsAsync(cardId);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 用户会员卡新增
        /// </summary>
        [HttpPost("usercard_add")]
        public async Task<UnaryResult> AddUserCardAsync(VenueUserCardAddDto model)
        {
            var result = await _venueUserCardService.AddAsync(model);
            return result;
        }

        /// <summary>
        /// 用户会员卡删除
        /// </summary>
        /// <param name="userCardId">用户会员卡ID</param>
        /// <returns></returns>
        [HttpPost("usercard_delete")]
        public async Task<UnaryResult> DeleteUserCardAsync([FromForm] Guid userCardId)
        {
            var result = await _venueUserCardService.DeleteAsync(userCardId);
            return result;
        }

        /// <summary>
        /// 用户会员卡充值
        /// </summary>
        [HttpPost("usercard_recharge")]
        public async Task<UnaryResult> UserCardRechargeAsync(VenueUserCardAmountAddDto model)
        {
            var result = await _venueUserCardService.RechargeAsync(model);
            return result;
        }

        /// <summary>
        /// 用户会员卡记录分页
        /// </summary>
        [HttpPost("usercard_record_pagelist")]
        public async Task<UnaryResult<PageResult<VenueUserCardRecordDto>>> UserCardRecordPageListAsync(VenueUserCardRecordPageRequestDto model)
        {
            var result = await _venueUserCardRecordService.PageListAsync(model);
            return UnaryResult.From(0, result);
        }
    }
}
